package Thread;
//使用实现Runnable的方式创建线程
class MyRunnable implements Runnable{
    @Override
    public void run() {
        while (true){
            System.out.println("hello Thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        MyRunnable myRunnable = new MyRunnable();
        Thread t = new Thread(myRunnable);//将实现了Runnable接口的类实例化的对象传入到Thread的构造函数里面，实例化Thread对象，再利用start创建线程
        t.start();//
        while (true){
            System.out.println("hello Main");
            Thread.sleep(1000);
        }
    }
}
